import { IMapConfig, MarkerOption } from 'types/map';
export default class MineMap {
    map: any;
    markerData: {};
    constructor(config?: IMapConfig) {
        this.map = this.infoMap(config);
        this.markerData = {};
    }
    private infoMap(config?: IMapConfig) {
        minemap.domainUrl = CONFIG.domainUrl;
        minemap.dataDomainUrl = CONFIG.dataDomainUrl;
        minemap.serverDomainUrl = CONFIG.serverDomainUrl;
        minemap.spriteUrl = CONFIG.spriteUrl;
        minemap.serviceUrl = CONFIG.serviceUrl;
        minemap.key = CONFIG.key;
        minemap.solution = CONFIG.solution;
        return new minemap.Map({ ...CONFIG.mapConfig, ...config });
    }
    public marker(option: MarkerOption = {}) {
        const {
            id = dayjs().valueOf(),
            className,
            image = 'url(https://minedata.cn/nce-static/support/demo/js-api/zh/images/park-blue2x.png)',
            offset = [-12, -38],
            lnglat,
            click
        } = option;
        const el = document.createElement('div');
        el.id = id;
        el.className = 'marker ' + className;
        el.style.backgroundImage = image;
        click && (el.onclick = click);
        const marker = new minemap.Marker(el, { offset }).setLngLat(lnglat || this.map.getCenter()).addTo(this.map);
        (this.markerData as any)[id] = marker;
    }
}
